import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'

// 表单校验
export const rules = reactive({
  siteId: [required],
  userId: [required],
  name: [required],
  beginTime: [required],
  currentNum: [required],
  totalNum: [required],
  taskType: [required],
  status: [required]
})

const crudSchemas = reactive<CrudSchema[]>([
  {
    label: '任务ID',
    field: 'id',
    isForm: false
  },
  {
    label: '名称',
    field: 'name',
    isSearch: true
  },
  {
    label: '用户ID',
    field: 'userId',
    isSearch: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '开始时间',
    field: 'beginTime',
    formatter: dateFormatter,
    isSearch: false,
    form: {
      component: 'DatePicker',
      componentProps: {
        type: 'datetime',
        valueFormat: 'x'
      }
    }
  },
  {
    label: '结束时间',
    field: 'endTime',
    formatter: dateFormatter,
    isSearch: false,
    form: {
      component: 'DatePicker',
      componentProps: {
        type: 'datetime',
        valueFormat: 'x'
      }
    }
  },
  {
    label: '已完成数量',
    field: 'currentNum',
    isSearch: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '总数量',
    field: 'totalNum',
    isSearch: false,
    isTable: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '类型',
    field: 'taskType',
    isSearch: false,
    isTable: false,
    form: {
      component: 'SelectV2'
    }
  },
  {
    label: '状态',
    field: 'status',
    isSearch: true,
    form: {
      component: 'Radio'
    }
  },
  {
    label: '错误信息',
    field: 'errorMsg',
    isSearch: false,
    isTable: false
  },
  {
    label: '操作',
    field: 'action',
    isForm: false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
